package com.hds.common.utils;

import java.util.Random;

/**
 * @Author guonan
 * @Email guonan@yewcn.com
 * @Description 激活码生成
 * @Date 2018/6/11 9:52
 */
public class ActivateCodeGenerator {

    /**
     * 输入一个数字：空位补零
     * 1-001
     * @param num
     */
    public static String convert3Str(Integer num){
        String str = String.format("%3d", num).replace(" ", "0");
        return str;
    }


    public static String genRandomNum(){
        int  maxNum = 34; //字母个数(25: 去掉了字母'O')+数字个数(9: 去掉了数字'0')
        int i;
        int count = 0;
        // 去掉了字母'O'和数字'0'
        char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while(count < 6){
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count ++;
            }
        }
        return pwd.toString();
    }

    public static void main(String[] args) {
        System.out.println(genRandomNum());
    }
}
